<h2>DESCRIPTION</h2>

<em>i.modis.qc</em> extracts Requested Quality Assessment flags from the
following MODIS products: MOD09A1, MOD09Q1, MOD11A1, MOD11A2, MOD13A2, MOD13Q1,
MCD43B2. This does include MOD09A1 QA_state_500m layer (see Notes).
<br>
Added MOD09GA support in 2016, it follows MOD09A1 and its StateQA, but does not have BRDF State QA, instead has Salt Pan State QA.

<h3>MOD09A1 and MOD09Q1</h3>
<pre>
<em>MOD09A1/Q1: MODLAND QA Bits. bits=[0-1]</em>
</pre>
<ul>
 <li>[00]= class 0: Corrected product produced at ideal quality -- all bands</li>
 <li>[01]= class 1: Corrected product produced at less than ideal quality -- some or all bands</li>
 <li>[10]= class 2: Corrected product NOT produced due to cloud effect -- all bands</li>
 <li>[11]= class 3: Corrected product NOT produced due to other reasons --
 some or all bands maybe be fill value (Note that a value of [11] overrides a value of [01])</li>
</ul>

<pre>
<em>MOD09Q1: Cloud State. bits=[2-3] </em>
</pre>
<ul>
 <li>[00]= class 0: Clear -- No clouds</li>
 <li>[01]= class 1: Cloudy</li>
 <li>[10]= class 2: Mixed</li>
 <li>[11]= class 3: Not Set ; Assumed Clear</li>
</ul>

<pre>
<em>MOD09Q1: Band-wise Data Quality 250m bits=[4-7][8-11]</em>
<em>MOD09A1: Band-wise Data Quality 500m bits=[2-5][6-9][10-13][14-17][18-21][22-25][26-29]</em>
</pre>
<ul>
 <li>[0000]= class 0: highest quality</li>
 <li>[0111]= class 1: noisy detector</li>
 <li>[1000]= class 2: dead detector; data interpolated in L1B</li>
 <li>[1001]= class 3: solar zenith &ge; 86 degrees</li>
 <li>[1010]= class 4: solar zenith &ge; 85 and &lt; 86 degrees</li>
 <li>[1011]= class 5: missing input</li>
 <li>[1100]= class 6: internal constant used in place of climatological data for at least one atmospheric constant</li>
 <li>[1101]= class 7: correction out of bounds, pixel constrained to extreme allowable value</li>
 <li>[1110]= class 8: L1B data faulty</li>
 <li>[1111]= class 9: not processed due to deep ocean or cloud</li>
 <li>Class 10-15: Combination of bits unused</li>
</ul>

<pre>
<em>MOD09A1/Q1: Atmospheric correction bit=[12]/[30]</em>
</pre>
<ul>
 <li>[0]= class 0: Not Corrected product</li>
 <li>[1]= class 1: Corrected product</li>
</ul>

<pre>
<em>MOD09A1/Q1: Adjacency correction bit=[13]/[31]</em>
</pre>
<ul>
 <li>[0]= class 0: Not Corrected product</li>
 <li>[1]= class 1: Corrected product</li>
</ul>

<pre>
<em>MOD09Q1: Different orbit from 500m product, bit=[14]</em>
</pre>
<ul>
 <li>[0]= class 0: same orbit as 500m</li>
 <li>[1]= class 1: different orbit from 500m</li>
</ul>

<pre>
<em>MOD09A1s: Cloud State bits=[0-1]</em>
</pre>
<ul>
 <li>[00]= class 0: clear</li>
 <li>[01]= class 1: cloudy</li>
 <li>[10]= class 2: mixed</li>
 <li>[11]= class 3: not set, assumed clear</li>
</ul>

<pre>
<em>MOD09A1s: Cloud shadow bits=[2]</em>
</pre>
<ul>
 <li>[0]= class 0: no</li>
 <li>[1]= class 1: yes</li>
</ul>

<pre>
<em>MOD09A1s: Land/Water Flag bits=[3-5]</em>
</pre>
<ul>
 <li>[000]= class 0: Shallow ocean</li>
 <li>[001]= class 1: Land</li>
 <li>[010]= class 2: Ocean coastlines and lake shorelines</li>
 <li>[011]= class 3: Shallow inland water</li>
 <li>[100]= class 4: Ephemeral water</li>
 <li>[101]= class 5: Deep inland water</li>
 <li>[110]= class 6: Continental/moderate ocean</li>
 <li>[111]= class 7: Deep ocean</li>
</ul>

<pre>
<em>MOD09A1s: Aerosol Quantity bits=[6-7]</em>
</pre>
<ul>
 <li>[00]= class 0: Climatology</li>
 <li>[01]= class 1: Low</li>
 <li>[10]= class 2: Average</li>
 <li>[11]= class 3: High</li>
</ul>

<pre>
<em>MOD09A1s: Cirrus detected bits=[8-9]</em>
</pre>
<ul>
 <li>[00]= class 0: None</li>
 <li>[01]= class 1: Small</li>
 <li>[10]= class 2: Average</li>
 <li>[11]= class 3: High</li>
</ul>

<pre>
<em>MOD09A1s: Internal Cloud Algorithm Flag bits=[10]</em>
</pre>
<ul>
 <li>[0]= class 0: No cloud</li>
 <li>[1]= class 1: Cloud</li>
</ul>

<pre>
<em>MOD09A1s: Internal Fire Algorithm Flag bits=[11]</em>
</pre>
<ul>
 <li>[0]= class 0: No fire</li>
 <li>[1]= class 1: Fire</li>
</ul>

<pre>
<em>MOD09A1s: MOD35 snow/ice flag bits=[12]</em>
</pre>
<ul>
 <li>[0]= class 0: No</li>
 <li>[1]= class 1: Yes</li>
</ul>

<pre>
<em>MOD09A1s: Pixel adjacent to cloud bits=[13]</em>
</pre>
<ul>
 <li>[0]= class 0: No</li>
 <li>[1]= class 1: Yes</li>
</ul>

<pre>
<em>MOD09A1s: BRDF correction performed bits=[14]</em>
</pre>
<ul>
 <li>[0]= class 0: No</li>
 <li>[1]= class 1: Yes</li>
</ul>

<pre>
<em>MOD09A1s: Internal Snow Mask bits=[15]</em>
</pre>
<ul>
 <li>[0]= class 0: No snow</li>
 <li>[1]= class 1: Snow</li>
</ul>


<h3>MOD11A1</h3>
<pre>
<em>MOD11A1: Mandatory QA Flags bits=[0-1]</em>
</pre>
<ul>
 <li>[00]= class 0: LST produced, good quality, not necessary to examine more detailed QA</li>
 <li>[01]= class 1: LST produced, other quality, recommend examination of more detailed QA</li>
 <li>[10]= class 2: LST not produced due to cloud effects</li>
 <li>[11]= class 3: LST not produced primarily due to reasons other than cloud</li>
</ul>

<pre>
<em>MOD11A1: Data Quality Flag bits=[2-3]</em>
</pre>
<ul>
 <li>[00]= class 0: Good data quality of L1B in bands 31 and 32</li>
 <li>[01]= class 1: Other quality data</li>
 <li>[10]= class 2: TBD</li>
 <li>[11]= class 3: TBD</li>
</ul>

<pre>
<em>MOD11A1: Emis Error Flag bits=[4-5]</em>
</pre>
<ul>
 <li>[00]= class 0: Average emissivity error &le; 0.01</li>
 <li>[01]= class 1: Average emissivity error &le; 0.02</li>
 <li>[10]= class 2: Average emissivity error &le; 0.04</li>
 <li>[11]= class 3: Average emissivity error &gt; 0.04</li>
</ul>

<pre>
<em>MOD11A1: LST Error Flag bits=[6-7]</em>
</pre>
<ul>
 <li>[00]= class 0: Average LST error &le; 1</li>
 <li>[01]= class 1: Average LST error &le; 2</li>
 <li>[10]= class 2: Average LST error &le; 3</li> 
 <li>[11]= class 3: Average LST error &gt; 3</li>
</ul>

<h3>MOD11A2</h3>
<pre>
<em>MOD11A2: Mandatory QA Flags bits=[0-1]</em>
</pre>
<ul>
 <li>[00]= class 0: LST produced, good quality, not necessary to examine more detailed QA</li>
 <li>[01]= class 1: LST produced, other quality, recommend examination of more detailed QA</li>
 <li>[10]= class 2: LST not produced due to cloud effects</li>
 <li>[11]= class 3: LST not produced primarily due to reasons other than cloud</li>
</ul>

<pre>
<em>MOD11A2: Data Quality Flag bits=[2-3]</em>
</pre>
<ul>
 <li>[00]= class 0: Good data quality of L1B in 7 TIR bands</li>
 <li>[01]= class 1: Other quality data</li>
 <li>[10]= class 2: TBD</li>
 <li>[11]= class 3: TBD</li>
</ul>

<pre>
<em>MOD11A2: Emis Error Flag bits=[4-5]</em>
</pre>
<ul>
 <li>[00]= class 0: Average emissivity error &le; 0.01</li>
 <li>[01]= class 1: Average emissivity error &le; 0.02</li>
 <li>[10]= class 2: Average emissivity error &le; 0.04</li>
 <li>[11]= class 3: Average emissivity error &gt; 0.04</li>
</ul>

<pre>
<em>MOD11A2: LST Error Flag bits=[6-7]</em>
</pre>
<ul>
 <li>[00]= class 0: Average LST error &le; 1</li>
 <li>[01]= class 1: Average LST error &le; 2</li>
 <li>[10]= class 2: Average LST error &le; 3</li> 
 <li>[11]= class 3: Average LST error &gt; 3</li>
</ul>

<h3>MOD13A2</h3>
<pre>
<em>MOD13A2: Mandatory QA Flags 1km bits[0-1]</em>
</pre>
<ul>
 <li>[00]= class 0: VI produced, good quality</li>
 <li>[01]= class 1: VI produced, but check other QA</li>
 <li>[10]= class 2: Pixel produced, but most probably cloud</li>
 <li>[11]= class 3: Pixel not produced due to other reasons than clouds</li>
</ul>

<pre>
<em>MOD13A2: VI Usefulness Flag bits[2-5]</em>
</pre>
<ul>
 <li>[0000]= class 0: Highest quality</li>
 <li>[0001]= class 1: Lower quality</li>
 <li>[0010]= class 2: Decreasing quality</li>
 <li>[0100]= class 3: Decreasing quality</li>
 <li>[1000]= class 4: Decreasing quality</li>
 <li>[1001]= class 5: Decreasing quality</li>
 <li>[1010]= class 6: Decreasing quality</li>
 <li>[1100]= class 7: Lowest quality</li>
 <li>[1101]= class 8: Quality so low that it is not useful</li>
 <li>[1110]= class 9: L1B data faulty</li>
 <li>[1111]= class 10: Not useful for any other reason/not processed</li>
</ul>

<pre>
<em>MOD13A2: Aerosol quantity Flags 1km bits[6-7]</em>
</pre>
<ul>
 <li>[00]= class 0: Climatology</li>
 <li>[01]= class 1: Low</li>
 <li>[10]= class 2: Average</li>
 <li>[11]= class 3: High</li>
</ul>

<pre>
<em>MOD13A2: Adjacent cloud detected 1km bit[8]</em>
</pre>
<ul>
 <li>[00]= class 0: No</li>
 <li>[01]= class 1: Yes</li>
</ul>

<pre>
<em>MOD13A2: Atmosphere BRDF correction performed 1km bit[9]</em>
</pre>
<ul>
 <li>[00]= class 0: No</li>
 <li>[01]= class 1: Yes</li>
</ul>

<pre>
<em>MOD13A2: Mixed clouds 1km bit[10]</em>
</pre>
<ul>
 <li>[00]= class 0: No</li>
 <li>[01]= class 1: Yes</li>
</ul>

<pre>
<em>MOD13A2: Land/Water Flags 1km bits[11-13]</em>
</pre>
<ul>
 <li>[000]= class 0: Shallow Ocean</li>
 <li>[001]= class 1: Land (Nothing else but land)</li>
 <li>[010]= class 2: Ocean Coastlines and lake shorelines</li>
 <li>[011]= class 3: Shallow inland water</li>
 <li>[100]= class 4: Ephemeral water</li>
 <li>[101]= class 5: Deep inland water</li>
 <li>[110]= class 6: Moderate or continental ocean</li>
 <li>[111]= class 7: Deep ocean</li>
</ul>

<pre>
<em>MOD13A2: Possible Snow/Ice 1km bits[14]</em>
</pre>
<ul>
 <li>[0]= class 0: No</li>
 <li>[1]= class 1: Yes</li>
</ul>

<pre>
<em>MOD13A2: Possible Shadow 1km bits[15]</em>
</pre>
<ul>
 <li>[0]= class 0: No</li>
 <li>[1]= class 1: Yes</li>
</ul>

<h3>MOD13Q1</h3>
<pre>
<em>MOD13Q1: Mandatory QA Flags 250m bits[0-1]</em>
</pre>
<ul>
 <li>[00]= class 0: VI produced, good quality</li>
 <li>[01]= class 1: VI produced, but check other QA</li>
 <li>[10]= class 2: Pixel produced, but most probably cloud</li>
 <li>[11]= class 3: Pixel not produced due to other reasons than clouds</li>
</ul>

<pre>
<em>MOD13Q1: VI Usefulness Flag 250m bits[2-5]</em>
</pre>
<ul>
 <li>[0000]= class 0: Highest quality</li>
 <li>[0001]= class 1: Lower quality</li>
 <li>[0010]= class 2: Decreasing quality</li>
 <li>[0100]= class 3: Decreasing quality</li>
 <li>[1000]= class 4: Decreasing quality</li>
 <li>[1001]= class 5: Decreasing quality</li>
 <li>[1010]= class 6: Decreasing quality</li>
 <li>[1100]= class 7: Lowest quality</li>
 <li>[1101]= class 8: Quality so low that it is not useful</li>
 <li>[1110]= class 9: L1B data faulty</li>
 <li>[1111]= class 10: Not useful for any other reason/not processed</li>
</ul>

<pre>
<em>MOD13Q1: Aerosol quantity Flags 250m bits[6-7]</em>
</pre>
<ul>
 <li>[00]= class 0: Climatology</li>
 <li>[01]= class 1: Low</li>
 <li>[10]= class 2: Average</li>
 <li>[11]= class 3: High</li>
</ul>

<pre>
<em>MOD13Q1: Adjacent cloud detected 250m bit[8]</em>
</pre>
<ul>
 <li>[00]= class 0: No</li>
 <li>[01]= class 1: Yes</li>
</ul>

<pre>
<em>MOD13Q1: Atmosphere BRDF correction performed 250m bit[9]</em>
</pre>
<ul>
 <li>[00]= class 0: No</li>
 <li>[01]= class 1: Yes</li>
</ul>

<pre>
<em>MOD13Q1: Mixed clouds 250m bit[10]</em>
</pre>
<ul>
 <li>[00]= class 0: No</li>
 <li>[01]= class 1: Yes</li>
</ul>

<pre>
<em>MOD13Q1: Land/Water Flags 250m bits[11-13]</em>
</pre>
<ul>
 <li>[000]= class 0: Shallow Ocean</li>
 <li>[001]= class 1: Land (Nothing else but land)</li>
 <li>[010]= class 2: Ocean Coastlines and lake shorelines</li>
 <li>[011]= class 3: Shallow inland water</li>
 <li>[100]= class 4: Ephemeral water</li>
 <li>[101]= class 5: Deep inland water</li>
 <li>[110]= class 6: Moderate or continental ocean</li>
 <li>[111]= class 7: Deep ocean</li>
</ul>

<pre>
<em>MOD13Q1: Possible Snow/Ice 250m bits[14]</em>
</pre>
<ul>
 <li>[0]= class 0: No</li>
 <li>[1]= class 1: Yes</li>
</ul>

<pre>
<em>MOD13Q1: Possible Shadow 250m bits[15]</em>
</pre>
<ul>
 <li>[0]= class 0: No</li>
 <li>[1]= class 1: Yes</li>
</ul> 

<h3>MCD43B2</h3>
<pre>
<em>MCD43B2: Albedo Quality Ancillary Platform Data 1km bits[0-3]</em>
<em>SDS: BRDF_Albedo_Ancillary</em>
</pre>
<ul>
 <li>[0000]= class 0: Satellite Platform: Terra</li>
 <li>[0001]= class 1: Satellite Platform: Terrra/Aqua</li>
 <li>[0010]= class 2: Satellite Platform: Aqua</li>
 <li>[1111]= class 15: Fill Value</li>
 <li>Classes 3-14: Not used</li>
</ul>

<pre>
<em>MCD43B2: Albedo Quality Ancillary Land/Water Data 1km bits[4-7]</em>
<em>SDS: BRDF_Albedo_Ancillary</em>
</pre>
<ul>
 <li>[0000] class 0: Shallow Ocean</li>
 <li>[0001] class 1: Land (Nothing else but land)</li>
 <li>[0010] class 2: Ocean and lake shorelines</li>
 <li>[0011] class 3: Shallow inland water</li>
 <li>[0100] class 4: Ephemeral water</li>
 <li>[0101] class 5: Deep inland water</li>
 <li>[0110] class 6: Moderate or continental ocean</li>
 <li>[0111] class 7: Deep ocean</li>
 <li>[1111] class 15: Fill Value</li>
 <li>Classes 8-14: Not used</li>
</ul>

<pre>
<em>MCD43B2: Albedo Quality Ancillary Sun Zenith Angle at Local Solar Noon Data 1km bits[8-14]</em>
<em>SDS: BRDF_Albedo_Ancillary</em>
</pre>
<ul>
   Returns integer value [0-90], 127 is Fill Value
</ul>


<pre>
<em>MCD43B2: Band-wise Albedo Quality Data 1km</em>
<em>SDS: BRDF_Albedo_Band_Quality</em>
</pre>
bits[0-3][4-7][8-11][12-15][16-19][20-23][24-27]<br>
<ul>
 <li>[0000]= class 0: best quality, 75% or more with best full inversions</li>
 <li>[0001]= class 1: good quality, 75% or more with full inversions</li>
 <li>[0010]= class 2: Mixed, 50% or less full inversions and 25% or less fill values</li> 
 <li>[0011]= class 3: All magnitude inversions or 50% or less fill values</li> 
 <li>[0100]= class 4: 75% or more fill values</li> 
 <li>Classes 5-14: Not Used</li>
 <li>[1111]= class 15: Fill Value</li>
</ul>


<h2>NOTES</h2>
In MOD09A1: It seems that cloud related info is not filled properly in the
standard QC (MOD09A1 in this module) since version 3, State-QA 500m images
(MOD09A1s in this module) should be used (see Vermote et al., 2008).

MOD11A2 quality control (QC) bands do not have a FillValue (No-data) according 
to <a href="https://lpdaac.usgs.gov/dataset_discovery/modis/modis_products_table/mod11a2_v006">MODIS Land Products site</a>. 
However, the metadata of the QC bands (i.e.: <tt>gdalinfo QC_band</tt>) shows <tt>No-data=0</tt>. 
This value is then transformed into GRASS NULLs when data is imported through 
<a href="r.in.gdal.html">r.in.gdal</a>. Applying <em>i.modis.qc</em> on those QC bands
will not give the expected range of values in the different QC bits. Therefore, 
before using <em>i.modis.qc</em>, the user needs to set the NULL value in QC bands 
back to zero (i.e.: <tt>r.null map=QC_band null=0</tt>) or just edit the metadata with GDAL 
utilities before importing into GRASS GIS. This is a known issue for MOD11A2 
(8-day LST product), but other MODIS products might be affected as well.


<h2>TODO</h2>
Add more daily products.

<h2>SEE ALSO</h2>

<em>
<a href="i.vi.html">i.vi</a>
</em>

<h2>REFERENCES</h2>

<ul>
<li> <a href="https://lpdaac.usgs.gov/dataset_discovery/modis/modis_products_table">MODIS Products</a>
<li> Vermote E.F., Kotchenova S.Y., Ray J.P. MODIS Surface Reflectance User's Guide. 
 Version 1.2. June 2008. MODIS Land Surface Reflectance Science Computing Facility.
 <a href="http://modis-sr.ltdri.org">Homepage</a>
</ul>

<h2>AUTHOR</h2>
Yann Chemin

<!--
<p>
<i>Last changed: $Date$</i>
-->
